package me.jzn.alib.drawable;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RemoteViews;

import androidx.annotation.IdRes;

import me.jzn.alib.ALib;

public class BitmapDrawableType implements DrawableType {
    private Bitmap bitmap;

    public BitmapDrawableType(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public Bitmap getBitmap() {
        return bitmap;
    }

    @Override
    public Drawable getDrawable() {
        return new BitmapDrawable(ALib.app().getResources(), bitmap);
    }

    @Override
    public void setImageView(ImageView iv) {
        iv.setImageBitmap(bitmap);
    }

    @Override
    public void setBackground(View view) {
        view.setBackground(new BitmapDrawable(view.getContext().getResources(), bitmap));
    }

    @Override
    public void setRemoteViews(RemoteViews rv, @IdRes int imageViewId) {
        rv.setImageViewBitmap(imageViewId, bitmap);
    }
}
